/*
 * Supports different colour schemes, tiles, etc.
 * Also loads images, etc..
 */

import java.util.HashMap;
import processing.core.*;

public class Theme {
	public static Theme current; // the current theme, this field is accessed by things wanting theme elements
	
	public Theme(processing.core.PApplet app)
	{
		// directory to find this themes goodies
		final String imgDir = "img/muted/";
		
		font = app.loadFont("BorisBlackBloxx-32.vlw");
		
		// load tile images
		tileImageMap = new HashMap<String,PImage>();
		// for this theme we load just one image, and extract the individual iamges from that
		PImage tileimg = app.loadImage(imgDir + "tiles.png");
		imgWidth = 47;
		imgHeight = 47;
		int index = 0;
		for (String str: TileFactory.tileNames)
		{
			tileImageMap.put(str,tileimg.get(index*imgWidth,0,imgWidth,imgHeight));
			index++;
		}
		
		tileShadowImg = app.loadImage(imgDir + "shadow.png");
		
		// load meeple images
		int MAXPLAYERS = 4;
		String imgMeeplesFileNames[] = {"meeple_orange.png","meeple_blue.png","meeple_black.png","meeple_yellow.png"};
		imgMeeples = new PImage[MAXPLAYERS];
		for(int i=0;i<MAXPLAYERS;i++)
			imgMeeples[i] = app.loadImage(imgDir + imgMeeplesFileNames[i]);
		
		// load 2,3,4 player icons
		imgNumPlayerSelection = new PImage[3];
		for(int i=0;i<3;i++)
			imgNumPlayerSelection[i] = app.loadImage(imgDir + (i+2) + "player.png");		
	}
	
	// a theme must specify the following things...
	public PFont font;
	public void setBackgroundFill(PApplet app)
	{
		//app.background(230,205,122);
		app.background(243,204,69);
	}
	
	public int backgroundColour(PApplet app)
	{
		return app.color(243,204,69);
	}
	
	public int playerColour(PApplet app, int p)
	{
		int cols[] = {app.color(213,112,45), app.color(179,197,197), app.color(27,55,16), app.color(246,203,24)};
		return cols[p];
	}
	
	public PImage getTileImage(Tile t)
	{
		return tileImageMap.get(t.tile);
	}
	public PImage getTileShadowImage()
	{
		return tileShadowImg;
	}
	public PImage getMeepleImage(int player)
	{
		return imgMeeples[player];
	}
	public int getTileWidth()
	{
		return imgWidth;
	}
	public int getTileHeight()
	{
		return imgHeight;
	}
	
	public PImage getNumPlayerSelection(int np)
	{
		return imgNumPlayerSelection[np-2];
	}
	
	private int imgWidth;
	private int imgHeight;
	private PImage[] imgMeeples;
	private PImage tileShadowImg;
	private HashMap<String,PImage> tileImageMap;
	private PImage[] imgNumPlayerSelection;
}
